var preview = new Vue({
	el: "#app",
	data: {
		points: 0,
		defaultAddr: false,
		shopCarIds: [],
		address: {},
		shopList: [],
		kou_credit: 0,
		fixes_price: 0,
		zugou: true,
		all_credit: 0,
		remark: "",
		openid:"",
		orderNo:"",
		requestUrl:""
	},
	methods: {
		previewOrder: function() {
			var t = this;
			wx.showLoading({
				title: "加载中",
				mask: !0
			}), this.$http.post(baseUrl + "order/preview", {
				shopCarIds: JSON.stringify(t.shopCarIds)
			}).then(function(e) {
				wx.hideLoading();
				var i = e.data;
				if (!i.success) return wx.hideLoading(), wx.showToast({
					title: i.description,
					icon: "none",
					duration: 2e3,
					mask: !0
				}), setTimeout(function() {
					Jump.back();
				}, 1500), !1;
				var totalPoints = 0;
				i.data.orderDetails.forEach(function(e) {
					totalPoints += e.points;
				});
				t.shopList = i.data.orderDetails, t.all_credit = parseFloat(i.data.points), t.all_price = parseFloat(i.data.originPrice)
					.toFixed(2);
				t.kou_credit = parseInt(i.data.points);
				t.fixes_price = parseFloat(i.data.amount).toFixed(2);
				t.zugou = t.kou_credit >= totalPoints;
			}).catch(function(t) {
				wx.hideLoading(), wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		get_user_points: function() {
			var t = this;
			this.$http.post(baseUrl + "mjz/user/query/points", {}).then(function(e) {
				var i = e.data;
				if (!i.success) return wx.showToast({
					title: i.description,
					icon: "none",
					duration: 2e3,
					mask: !0
				});
				if (i.data) {
					t.points = i.data;
				} else {
					t.points = 0;
				}
			}).catch(function(t) {
				wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		get_user_address: function() {
			var t = this;
			this.$http.post(baseUrl + "address/list", {
				fetchAll: true
			}).then(function(e) {
				var i = e.data;
				if (!i.success) return wx.showToast({
					title: i.description,
					icon: "none",
					duration: 2e3,
					mask: !0
				});
				t.defaultAddr = false;
				if (i.data && i.data.length != 0) {
					i.data.forEach(function(e) {
						if (e.default) {
							t.address = e;
							t.defaultAddr = true;
						}
					});
				}
			}).catch(function(t) {
				wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		submitOrder: function() {
			var isInvalidAddr = !this.address || !this.address.addressGuid;
			if (isInvalidAddr) {
				wx.showToast({
					title:"收货地址不能为空!"
				});
				return;
			}
			wx.showLoading({
				title: "加载中",
				mask: !0
			});
			this.$http.post(baseUrl + "order/create", {
				shopCarIds: JSON.stringify(this.shopCarIds),
				addressGuid: this.address.addressGuid,
				remark: this.remark
			}).then(function(d) {
				wx.hideLoading();
				var i = d.data;
				if(!i.success){
					wx.showToast({
						title: i.description,
						icon: "none",
						duration: 2e3,
						mask: !0
					});
					setTimeout(function(){
						Jump.back();
					},1500)
				}else{
					wx.showLoading({title:"支付中..."});
					this.$http.post(baseUrl+"order/pay/appWx",{
						orderNo:i.data
					}).then(function(e){
						wx.hideLoading();
						var r = e.data;
						if(!r.success){
							 wx.showToast({
								title: r.description,
								icon: "none",
								duration: 2e3,
								mask: !0
							});
						}else{
							plus.webview.create(r.data, 'prod_pay_url1', {additionalHttpHeaders:{Referer:'https://app.meijiangzi.com/'}});
							Jump.to(page.pay.result, 'orderNo='+i.data+'&orderType=mjz');
							// window.location.href=r.data;
						}
					})
				}
			}).catch(function(e) {
				wx.hideLoading(), wx.showToast({
					title: "网络错误，请检查网络",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		toAddress:function(){
			Jump.to(page.address.index,"choose=true");
		}
	},
	created: function(e) {
		var ids = URLParam.get("ids");
		if (!ids) {
			Jump.back();
			return;
		}
		this.shopCarIds = JSON.parse(ids);
		this.previewOrder();
		var address_info = localStorage.getItem("address");
		this.openid = localStorage.getItem("open_id");
		if (address_info) {
			this.address = JSON.parse(address_info);
			this.defaultAddr = true;
		} else {
			this.get_user_address();
		}
		this.get_user_points();
	}
});
